#include "myview.h"

MyView::MyView()
{
    //1.窗口的大小
    this->setFixedSize(809,455);
    //2.标题
    this->setWindowTitle("开机界面");
    //3.背景图片
    this->setBackgroundBrush(QBrush(QPixmap(":/img/11.jpg")));
    //4.创建场景
    this->myScene = new QGraphicsScene();
    //5.给试图设置场景
    this->setScene(this->myScene);
    //6.左上角     scene中间     设置场景坐标与视图一致
    this->setSceneRect(0,0, this->width()-2,this->height()-2);
    //7.创建图元
    this->item1 = new MyItem(":/img/car_1.png", 1);
    this->car2 = new MyItem(":/img/comic.png", 2);
    //   this->item2 = new MyItem("img/weilan.png", 0);
    this->bomm = new MyItem(":/img/bom.png", 0);

    //8.把图元添加到场景中
    this->myScene->addItem(this->item1);
   // this->myScene->addItem(this->item2);
    this->myScene->addItem(this->car2);
    //9.设置图元位置
    this->item1->setPos(50, this->height()/2);
 //   this->item2->setPos(500,this->height()/2);
    this->car2->setPos(300,this->height()/2);
    //10.移动
    //10.1创建定时器
    this->timer1 = new QTimer(this);
    //设置一下每个多长时间发送超时信号
    this->timer1->start(40);  //msec 毫米   sec秒
    //advance----场景的槽函数
    connect(this->timer1, SIGNAL(timeout()), this->myScene, SLOT(advance()));
    connect(this->item1, SIGNAL(stopTimer()), this, SLOT(stopTimer1()));


}

//关闭定时器
void MyView::stopTimer1()
{
    this->timer1->stop();
//    Sleep(1000);
    //创建boom图元
    //添加
    this->myScene->addItem(this->bomm);
    //设置位置
    this->bomm->setPos(350,this->height()/2);

    //延迟1秒半
    Sleep(1500);
    //关闭开机界面
    this->close();
    //跳转至登陆界面
    this->s = new SetWidget();
    s->show();
}


//延迟函数
void MyView::Sleep(int msec)
{
    QTime dieTime = QTime::currentTime().addMSecs(msec);
    while(QTime::currentTime() < dieTime)
        QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}

